<template>
	<div id="index">
		<header id="indexNav">
			<div class="i_maxW i_headOne clear">
				<router-link to="/personal/index"  class="i_logo box">
					<img :src="BASE_URL + logo_url" alt="logo">
				</router-link>
			</div>
		</header>
		<div class="i_maxW">
			<div class="roomH">
				<img src="../../../public/images/bgc03.png">
			</div>
			<div class="roomP clear">
				<span class="fl">
					<img :src="BASE_URL + userData.avatar_path">
				</span>
				<div class="roomP_r">
					<div class="roomP_user clear">
						<div>
							<h3>{{userData.name}}</h3>
							<span v-if="userData.role_id === '4'">
								<strong >{{userData.org_name}}</strong>
							</span >
							<span v-else>
								<strong >{{userData.role_name}}</strong>
								<strong v-if="userData.sub_name &&  userData.sub_name != '暂未绑定科目' ">,{{userData.sub_name}}老师</strong>
							</span>
						</div>
						<!--  -->
						<div>
							<span @click="getFollow(userData.id)" v-if="userData.is_relation === 1" class="is_follow">
								<i class="ipm but_Collection01_up" ></i>
								已关注
							</span>
							<span @click="getFollow(userData.id)" v-else><i class="ipm but_Collection01_up" ></i>加关注</span>
							<router-link :to="{path: '/personal/contact/privateLette'}">
								<i class="ipm icon_sixin"></i>
								发私信
							</router-link>

						</div>
					</div>
					<!--  -->
					<div class="roomP_info" >
						<span>粉丝 {{userData.relation_num}}</span>
						<span>课程 {{userData.video_num}}</span>
						<span v-if="userData.sub_name &&  userData.sub_name != '暂未绑定科目' ">总播放量 {{userData.video_click}}</span>
						<span>资源总数 {{resource_sum}}</span>
					</div>
					<div class="roomP_synopsis">
						<P>
							{{userData.autograph}}
						</P>
					</div>
				</div>
			</div>
			<!--  -->
			<!--  -->
			<div class="room_content">
				<div class="menuLk box">
					<el-menu
					:default-active="activeIndex">
						<template v-for="(item, index) in menuNavRouteData.children">
							<el-menu-item :index="`'${index+1}'`">
								<i :class="`ipm ${item.icon}`"></i>
								<router-link 
								:to="'/'+menuNavRouteData.path+'/'+item.path+'/'+item.children[0].path+'?id=' + infoParam.id"
								:class="{'Indexactive':$route.path.split('/')[2] === item.path, 'activePath': isActivePath}"
								>
									{{item.txtName}}
								</router-link>
								<i class="ipm Shape_04"></i>
							</el-menu-item>
						</template>
					</el-menu>
				</div>
				<div class="room_cr box ">
					 <router-view/>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	export default{
		name: '',
		data() {
			return {
				infoParam:{
					id: this.$route.query.id,
					userid: this.$g.user_id
					// level:2,
				},
				infoResult:{
					avatar:'../../assets/images/Group9.png',
					name:'',
					subject_name:'',
					fans:0,
					courses:0,
					clicks:0,
					role: '',
					org_name: '',
					resource_num: 0,
					desc: '',
					id: ''
				},
				total_number:0,
				noticeList:[],
				errorImg: 'this.src="' + require('../../../public/images/image20.png') + '"',
				activeIndex: '1',
				menuNavRouteData: deep_clone(  this.$store.getters.leftMenuNav ),
				isActivePath: false,
				userData: {},
				resource_sum: '',
				logo_url: ''
			}
		},
		created(){
			this.getLogo()
			
		},
		mounted() {
			this.$nextTick(function () {
		    	// 代码保证 this.$el 在 document 中
		    	this.getInfo();
	       		this.getResourceList()
		 	})
		},
		methods: {
			getLogo(){
				let success = (res=>{
					this.logo_url = res.data[0].t_logo;
				})

				this.$ajax({
					url: 'api/system/get_logo',
					method: 'get',
					params: {},
					func: {success: success}
				})
			},
			getInfo(){
				let success = ( data =>{
					let res = data.data[0]
					this.userData = res
					if( process.env.NODE_ENV =='production' ){
					    this.infoResult.avatar = this.BASE_URL + res.avatar_path;
					}else{
					    this.infoResult.avatar  = this.BASE_URL + res.avatar_path;
					}

					this.infoResult.name = res.name;
					this.infoResult.subject_name = res.sub_name;
					this.infoResult.fans = res.relation_num;
					this.infoResult.courses = res.video_num;
					this.infoResult.clicks = res.video_click;
					this.infoResult.resource_num = res.resource_num;
					this.infoResult.role = parseInt(res.role_id)
					this.infoResult.org_name = res.org_name,
					this.infoResult.desc = res.autograph

	
					
					this.$store.commit('SET_SEND_USERINFO', {
						send_id: this.infoParam.id,
						avatar_path: this.infoResult.avatar,
						username: this.infoResult.name
					});


					this.menuNavRouteData.children.forEach(item =>{
						if (this.userData.id == this.$g.user_id) {
							//console.info(this.user_role.parent,10)
							if (item.txtName === 'TA的视频') {
								item.txtName = '我的视频'
							}else if (item.txtName === 'TA的资源') {
								item.txtName = '我的资源'
							}else if (item.txtName === 'TA的日志') {
								item.txtName = '我的日志'
							}else if (item.txtName === 'TA的粉丝') {
								item.txtName = '我的粉丝'
							}else if (item.txtName === 'TA的关注') {
								item.txtName = '我的关注'
							}
						}
					})




            	})
            	
            	//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
            	// this.$ajax.get('api/user/user_info',{params: this.infoParam,func:{success:success}})
            	this.$ajax.get('api/user/user',{params: this.infoParam,func:{success:success}})
			},
			getFollow(id){
				let success = ( res =>{
					this.$message.success(res.msg);
					this.getInfo()
				});

				this.$ajax({
					url: 'api/user/bind_relation',
					methods: 'post',
					data: {
						user_id: this.$g.user_id,
						follow_id: id,
						type: 0
					},
					func: {
						success: success
					}
				})
			},
			//学生==资源总数
			getResourceList(){
				let success = (res=>{
					let data = res.data
					this.resource_sum = data.data_sum
				})

           	//执行请求，并将回调方法变成config成员以便鉴权过期可以执行
           	this.$ajax.get('api/Resource/resource',{
           		params: {create_id: this.$route.query.id,authonity: 1,data_type: 2},
           		func:{success:success}
           	})
           },

		}
	}
</script>
